﻿//-----------------------------------------------------------------------
// <copyright file="AuctioneerTests.cs" company="Transilvania University of Brasov">
//     Copyright (c) Nagy Robert. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace TestDomainModel
{
    using DomainModel;
    using Microsoft.Practices.EnterpriseLibrary.Validation;
    using NUnit.Framework;

    /// <summary>
    /// Tests for the Auctioneer class
    /// </summary>
    [TestFixture]
    public class AuctioneerTests
    {
        /// <summary>
        /// Gets the valid auctioneer.
        /// </summary>
        private DTOAuctioneer ValidAuctioneer
        {
            get
            {
                return new DTOAuctioneer
                {
                    FirstName = "FirstName",
                    LastName = "LastName",
                    Id = 1,
                    Password = "Password",
                    Rating = 5,
                    Username = "Username"
                };
            }
        }
        
        /// <summary>
        /// Tests the username should not be null.
        /// </summary>
        [Test]
        public void TestUsernameShouldNotBeNull()
        {
            DTOAuctioneer auctioneer = this.ValidAuctioneer;
            auctioneer.Username = null;

            ValidationResults validationResults = Validation.Validate(auctioneer);
            Assert.IsFalse(validationResults.IsValid);
        }

        /// <summary>
        /// Tests the username length should not be valid.
        /// </summary>
        /// <param name="length">The length.</param>
        [Test]
        public void TestUsernameLengthShouldNotBeValid([Values(0, 1, 3, 51, 100)] int length)
        {
            string username = new string('a', length);
            DTOAuctioneer auctioneer = this.ValidAuctioneer;
            auctioneer.Username = username;

            ValidationResults validationResults = Validation.Validate(auctioneer);
            Assert.IsFalse(validationResults.IsValid);
        }

        /// <summary>
        /// Tests the username length should be valid.
        /// </summary>
        /// <param name="length">The length.</param>
        [Test]
        public void TestUsernameLengthShouldBeValid([Values(4, 25, 50)] int length)
        {
            string username = new string('a', length);
            DTOAuctioneer auctioneer = this.ValidAuctioneer;
            auctioneer.Username = username;

            ValidationResults validationResults = Validation.Validate(auctioneer);
            Assert.IsTrue(validationResults.IsValid);
        }

        /// <summary>
        /// Tests the first name should not be null.
        /// </summary>
        [Test]
        public void TestFirstNameShouldNotBeNull()
        {
            DTOAuctioneer auctioneer = this.ValidAuctioneer;
            auctioneer.FirstName = null;

            ValidationResults validationResults = Validation.Validate(auctioneer);
            Assert.IsFalse(validationResults.IsValid);
        }

        /// <summary>
        /// Tests the first name length should not be null.
        /// </summary>
        /// <param name="length">The length.</param>
        [Test]
        public void TestFirstNameLengthShouldNotBeValid([Values(0, 1, 51, 100)] int length)
        {
            string firstName = new string('a', length);
            DTOAuctioneer auctioneer = this.ValidAuctioneer;
            auctioneer.FirstName = firstName;

            ValidationResults validationResults = Validation.Validate(auctioneer);
            Assert.IsFalse(validationResults.IsValid);
        }

        /// <summary>
        /// Tests the first name length should be valid.
        /// </summary>
        /// <param name="length">The length.</param>
        [Test]
        public void TestFirstNameLengthShouldBeValid([Values(2, 25, 50)] int length)
        {
            string firstName = new string('a', length);
            DTOAuctioneer auctioneer = this.ValidAuctioneer;
            auctioneer.FirstName = firstName;

            ValidationResults validationResults = Validation.Validate(auctioneer);
            Assert.IsTrue(validationResults.IsValid);
        }

        /// <summary>
        /// Tests the last name should not be null.
        /// </summary>
        [Test]
        public void TestLastNameShouldNotBeNull()
        {
            DTOAuctioneer auctioneer = this.ValidAuctioneer;
            auctioneer.LastName = null;

            ValidationResults validationResults = Validation.Validate(auctioneer);
            Assert.IsFalse(validationResults.IsValid);
        }

        /// <summary>
        /// Tests the last name length should not be null.
        /// </summary>
        /// <param name="length">The length.</param>
        [Test]
        public void TestLastNameLengthShouldNotBeValid([Values(0, 1, 51, 100)] int length)
        {
            string lastName = new string('a', length);
            DTOAuctioneer auctioneer = this.ValidAuctioneer;
            auctioneer.LastName = lastName;

            ValidationResults validationResults = Validation.Validate(auctioneer);
            Assert.IsFalse(validationResults.IsValid);
        }

        /// <summary>
        /// Tests the last name length should be valid.
        /// </summary>
        /// <param name="length">The length.</param>
        [Test]
        public void TestLastNameLengthShouldBeValid([Values(2, 25, 50)] int length)
        {
            string lastName = new string('a', length);
            DTOAuctioneer auctioneer = this.ValidAuctioneer;
            auctioneer.LastName = lastName;

            ValidationResults validationResults = Validation.Validate(auctioneer);
            Assert.IsTrue(validationResults.IsValid);
        }

        /// <summary>
        /// Tests the password should not be null.
        /// </summary>
        [Test]
        public void TestPasswordShouldNotBeNull()
        {
            DTOAuctioneer auctioneer = this.ValidAuctioneer;
            auctioneer.Password = null;

            ValidationResults validationResults = Validation.Validate(auctioneer);
            Assert.IsFalse(validationResults.IsValid);
        }

        /// <summary>
        /// Tests the password length should not be null.
        /// </summary>
        /// <param name="length">The length.</param>
        [Test]
        public void TestPasswordLengthShouldNotBeValid([Values(0, 1, 5, 51, 100)] int length)
        {
            string password = new string('a', length);
            DTOAuctioneer auctioneer = this.ValidAuctioneer;
            auctioneer.Password = password;

            ValidationResults validationResults = Validation.Validate(auctioneer);
            Assert.IsFalse(validationResults.IsValid);
        }

        /// <summary>
        /// Tests the password length should be valid.
        /// </summary>
        /// <param name="length">The length.</param>
        [Test]
        public void TestPasswordLengthShouldBeValid([Values(6, 25, 50)] int length)
        {
            string password = new string('a', length);
            DTOAuctioneer auctioneer = this.ValidAuctioneer;
            auctioneer.Password = password;

            ValidationResults validationResults = Validation.Validate(auctioneer);
            Assert.IsTrue(validationResults.IsValid);
        }

        /// <summary>
        /// Tests the rating range should be invalid.
        /// </summary>
        /// <param name="rating">The rating.</param>
        [Test]
        public void TestRatingRangeShouldNotBeValid([Values(-10, -1, 11, 20)] int rating)
        {
            DTOAuctioneer auctioneer = this.ValidAuctioneer;
            auctioneer.Rating = rating;

            ValidationResults validationResults = Validation.Validate(auctioneer);
            Assert.IsFalse(validationResults.IsValid);
        }

        /// <summary>
        /// Tests the rating range should be invalid.
        /// </summary>
        /// <param name="rating">The rating.</param>
        [Test]
        public void TestRatingRangeShouldBeValid([Values(0, 5, 10)] int rating)
        {
            DTOAuctioneer auctioneer = this.ValidAuctioneer;
            auctioneer.Rating = rating;

            ValidationResults validationResults = Validation.Validate(auctioneer);
            Assert.IsTrue(validationResults.IsValid);
        }
    }
}
